#!/usr/bin/env ruby -wKU
#encoding: UTF-8

module Model
  
  class TChapter
    
    attr_accessor :chpName
    attr_accessor :volume # reference to volume instance
    attr_accessor :content
    attr_reader :chpNo
    
    def initialize(volume)
      @volume = volume
      @chpNo = 0
      @chpName = ""
      @content = ""
    end
    
    def chpNo=(chpNo)
      if chpNo > @volume.maxChpNo
        @volume.maxChpNo = chpNo
      end
      @chpNo = chpNo
    end
    
    def fileName
      @chpNo.to_s + "_" + @chpName
    end
	
    def storagePath
		  @volume.storageDir + "/" + fileName
    end
    
    def ==(o)
      o.class == self.class && o.state == state 
    end
    alias_method :eql?, :==
    
    def hash
      state.hash
    end
    
    def state
      @volume.state.concat([@chpNo, @chpName])
    end
  end
  
end
